package com.zjy.weather.data

import android.content.Context
import android.util.Log
import com.squareup.okhttp.Request
import com.zhy.http.okhttp.OkHttpUtils
import com.zhy.http.okhttp.callback.StringCallback
import com.zjy.weather.KEY
import com.zjy.weather.TAG
import com.zjy.weather.WEATHER_URL
import com.zjy.weather.base.RequestCallback
import java.lang.Exception


/**
 * Created by zhongjy on 2017/11/2.
 * Copyright (C) 2017 zhongjy. All rights reserved.
 */
object WeatherDataManager {

    fun getWeather(context: Context, location: String, callback: RequestCallback?) {
        Log.e(TAG, "getWeather-->$WEATHER_URL")
        OkHttpUtils.get()
                .url(WEATHER_URL)
                .addParams("location", location).addParams("key", KEY)
                .build()
                .execute(object : StringCallback() {
                    override fun onError(request: Request?, e: Exception?) {
                    }

                    override fun onResponse(response: String?) {
                        Log.d(TAG, "getWeather success$response")
                        callback?.let {
                            callback.onSuccess(response)
                        }
                    }
                })
    }
}
